import 'package:enterprise_v6_app/app/components/common/custom_no_data.dart';
import 'package:enterprise_v6_app/app/components/common/custom_tab_bar_widget.dart';
import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/process/approval_bottom_sheet.dart';
import 'package:enterprise_v6_app/app/components/process/approval_process_widget.dart';
import 'package:enterprise_v6_app/app/core/values/colors.dart';
import 'package:enterprise_v6_app/app/core/values/gaps.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/common/basic_common_widget.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/equipment_facilities/chain_removal_list/chain_removal_list_detail/chain_removal_list_detail_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

///联锁摘除清单详情
class ChainRemovalListDetailPage extends StatelessWidget {
  ChainRemovalListDetailPage({super.key});

  final controller = Get.put(ChainRemovalListDetailController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
              appBar: CustomAppBar(
                titleText: '联锁摘除清单台账详情',
              ),
              body: DefaultTabController(
                  length: 2,
                  child: Column(children: [
                    const CustomTabBarWidget(
                      tabs: [
                        Tab(text: '基本信息'),
                        Tab(text: '审批流程'),
                      ],
                    ),
                    Expanded(
                      child: TabBarView(
                        children: [
                          // 基本信息
                          _getBasicInfoView(),
                          // 流程数据
                          _getApprovalProcessView(),
                        ],
                      ),
                    ),
                    Visibility(visible: controller.isApproval, child: SizedBox(height: 230.w))
                  ])),
              bottomSheet: Visibility(
                visible: controller.isApproval,
                child: ApprovalBottomSheet(
                  onOpinion: controller.onOpinion,
                  onSign: controller.onSign,
                  onOperation: controller.onOperation,
                ),
              ));
        });
  }

  /// 基础信息
  Widget _getBasicInfoView() {
    if (controller.entity.id.isEmpty) {
      return const CustomNoData();
    }
    return Container(
        alignment: Alignment.topCenter,
        color: Colors.white,
        child: Column(
          children: [
            Container(
              height: 38.w,
              color: const Color(0xffF5F5F6),
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.only(left: 16.w, right: 16.w),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Expanded(
                    child: Text(
                      '基本信息',
                      style: TextStyle(
                        fontSize: 13.sp,
                        height: 1.2,
                        fontWeight: FontWeight.w400,
                        color: const Color(0xffA0A7B5),
                      ),
                    ),
                  ),
                  BasicCommonWidget.getCommonStateView(controller.entity.auditStatus),
                ],
              ),
            ),
            Container(
              height: 2.w,
              color: const Color(0xFF587DF5),
            ),
            Expanded(
                child: Container(
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 15.w),
              child: SingleChildScrollView(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    CustomTextWidget.getTextRowView(title: '名称：', value: controller.entity.name),
                    AppGaps.vGap10,
                    CustomTextWidget.getTextRowView(title: '操作人员：', value: controller.entity.inspector),
                    AppGaps.vGap10,
                    CustomTextWidget.getTextRowView(title: '开始日期：', value: controller.entity.startDate),
                    AppGaps.vGap10,
                    CustomTextWidget.getTextRowView(title: '结束日期：', value: controller.entity.endDate),
                    AppGaps.vGap10,
                    CustomTextWidget.getTextRowView(title: '摘除原因：', value: controller.entity.removalReason),
                  ],
                ),
              ),
            ))
          ],
        ));
  }

  /// 获取审批流程
  Widget _getApprovalProcessView() {
    return Column(
      children: [
        Container(
          height: 38.w,
          width: double.infinity,
          color: AppColors.bg_color_grey,
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 16.w),
          child: Text(
            '审批流程',
            style: TextStyle(
              fontSize: 12.sp,
              color: AppColors.text_grey,
            ),
          ),
        ),
        Container(
          height: 2.w,
          color: AppColors.blue_button,
        ),
        Expanded(child: ApprovalProcessWidget(nodeList: controller.nodeList)),
      ],
    );
  }
}
